package com.mdoya.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdoya.domain.SetmealDish;
import com.mdoya.mapper.SetmealDishMapper;
import com.mdoya.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author mdoya
 * @version 1.0
 * @description:
 */
@Scope("singleton")
@Transactional(propagation = Propagation.REQUIRED)
@Service
public class SetmealDishServiceImpl implements SetmealDishService {
    @Autowired
    private SetmealDishMapper setmealDishMapper;
    @Override
    public Integer add(SetmealDish setmealDish) {
        return setmealDishMapper.insert(setmealDish);
    }

    @Override
    public List<SetmealDish> findSetmealIdByList(Long setmealId) {
        LambdaQueryWrapper<SetmealDish> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SetmealDish::getSetmealId,setmealId);
        return setmealDishMapper.selectList(queryWrapper);
    }

    /**
     * 根据setmealId删除口味
     *
     * @param setmealId
     * @return
     */
    @Override
    public Integer deleteSetmealDish(Long setmealId) {
        LambdaQueryWrapper<SetmealDish> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SetmealDish::getSetmealId,setmealId);
        return setmealDishMapper.delete(queryWrapper);
    }

/*    *//**
     * 批量删除口味
     *
     * @param setmealDishes
     * @return
     *//*
    @Override
    public Integer batchdelete(List<SetmealDish> setmealDishes) {
        List<Integer> rows = setmealDishes.stream().map((e) -> {
            LambdaQueryWrapper<SetmealDish> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SetmealDish::getSetmealId, e.getSetmealId());
            return setmealDishMapper.delete(queryWrapper);
        }).collect(Collectors.toList());

        return rows.size();
    }*/

}
